package com.test4;


import com.alibaba.fastjson.JSONObject;
import com.test3.Executor;
import com.worktool.RestExecutor;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * 模拟并发
 * */
public class Test1 {



    public static void main(String[] args) {
        ThreadPoolExecutor tt = Executor.get();

        String url = "http://192.168.10.101:20000/lizhao/audio/view?id=27&openid=";

        RestTemplate restTemplate = RestExecutor.build();



//        CompletableFuture<Void> vo1 = CompletableFuture.runAsync(()->{
//            String path = url+"RuoYouShiWu1";
//            JSONObject json = restTemplate.getForObject(path, JSONObject.class);
//            System.err.println(json);
//        },tt);
//
//        CompletableFuture<Void> vo2 = CompletableFuture.runAsync(()->{
//            String path = url+"RuoYouShiWu2";
//            JSONObject json = restTemplate.getForObject(path, JSONObject.class);
//            System.err.println(json);
//        },tt);
//
//        CompletableFuture<Void> vo3 = CompletableFuture.runAsync(()->{
//            String path = url+"RuoYouShiWu3";
//            JSONObject json = restTemplate.getForObject(path, JSONObject.class);
//            System.err.println(json);
//        },tt);

        CompletableFuture<Void>[] arr = new CompletableFuture[101];
        for(int i =0;i<=100;i++){
            final int a = i;
            CompletableFuture<Void> vo3 = CompletableFuture.runAsync(()->{
                String path = url+"RuoYouShiWu"+a;
                JSONObject json = restTemplate.getForObject(path, JSONObject.class);
                System.err.println(json);
            },tt);

            arr[i] = vo3;
        }

        //CompletableFuture.allOf(arr);

        Map<String,String> map = new HashMap<>();

        map.put("aa","cc");
        map.put("bb","cc");

        for(Map.Entry<String,String> entry:map.entrySet()){
            System.err.println(entry);
        }

        //map.compute("aa",((key,value)->{return value.equals("cc")?"bb":"aa";}));

        map.computeIfAbsent("bb", e-> "a");

        map.computeIfPresent("dd",((key,value)-> value.equals("cc")?"bb":"aa"));


        for(Map.Entry<String,String> entry:map.entrySet()){
            System.err.println(entry);
        }

    }


}
